package com.jyt.CollectionServiceImp;

import org.junit.Test;

import com.jyt.baseUtil.RiZhiServlet;
import com.jyt.mockClientMsgBase.MockClientMsgBase_Tran;


public class MockClientMsg_TC1002 extends MockClientMsgBase_Tran {

	public static String TRAN_CODE = "TC1002";

	/**
	 * @throws Exception
	 */
	@Test
	public Infozhuangtai testTC1002_OK(String uid, String wlid, String tbankName,
			String tbankno, String tusername, String tbanktype,
			String ttranAmount, String tbsnCode, String tcertType,
			String tcertNo) throws Exception {
		// TODO Auto-generated constructor stub

		String bankName = tbankName;
		String accountNo = tbankno;
		String accountName = tusername;
		String accountType = "00";
		String tranAmt = ttranAmount;
		String bsnCode = tbsnCode;
		String certType = tcertType;
		String certNo = tcertNo;

		String xml = getTC1002Xml(bankName, accountNo, accountName,
				accountType, tranAmt, bsnCode, certType, certNo);
		System.out.println("���ͱ���" + xml);
		String mac = signMsg(xml);// ��ǩ�����̻���˽Կ���м�ǩ
		String respMsg = sendMsg(xml, mac);// ������Ӧ����
		String respCode = getMsgRespCode(respMsg);

		String tran_flowid = getMsgtran_flowid(respMsg);
		String resp_desc = getMsgresp_desc(respMsg);

		System.out.println("��Ӧ����" + respMsg);
		System.out.println("������" + respCode);

		Infozhuangtai infozhuangtai = new Infozhuangtai();

		infozhuangtai.setRespCode(respCode);
		infozhuangtai.setResp_desc(resp_desc);
		infozhuangtai.setTran_flowid(tran_flowid);
		
		
		
		double tranAmount1 = Double.parseDouble(tranAmt);
		new RiZhiServlet().zhifurizhi(tranAmount1, "�û����", uid, tran_flowid,
				"TC1002", wlid, respCode, resp_desc);

		return infozhuangtai;
	}

	/**
	 * @throws Exception
	 */
	@Test
	public void testTC1002_OK() throws Exception {
		String bankName = "�й���������";
		String accountNo = "6216919300010301";
		String accountName = "����";
		String accountType = "00";
		String tranAmt = "1.00";
		String bsnCode = "09400";
		String certType = "01";
		String certNo = "37132219920";

		String xml = getTC1002Xml(bankName, accountNo, accountName,
				accountType, tranAmt, bsnCode, certType, certNo);
		System.out.println("���ͱ���" + xml);
		String mac = signMsg(xml);// ��ǩ�����̻���˽Կ���м�ǩ
		String respMsg = sendMsg(xml, mac);// ������Ӧ����
		String respCode = getMsgRespCode(respMsg);
		System.out.println("��Ӧ����" + respMsg);
		System.out.println("������" + respCode);
	}

	/**
	 * ��װ���ʴ�TC1002����
	 * 
	 * @param bankName
	 * @param accountNo
	 * @param accountName
	 * @param accountType
	 * @param tranAmt
	 * @param bsnCode
	 * @param certType
	 * @param certNo
	 * @return
	 */
	public String getTC1002Xml(String bankName, String accountNo,
			String accountName, String accountType, String tranAmt,
			String bsnCode, String certType, String certNo) {
		StringBuffer xml = new StringBuffer();
		xml.append(getMsgHeadXml(TRAN_CODE));
		xml.append("<body><mer_viral_acct></mer_viral_acct>");
		xml.append("<agrt_no></agrt_no>").append("<bank_name>")
				.append(bankName).append("</bank_name>");
		xml.append("<account_no>").append(accountNo).append("</account_no>");
		xml.append("<account_name>").append(accountName)
				.append("</account_name>");
		xml.append("<account_type>").append(accountType)
				.append("</account_type>");
		xml.append("<brach_bank_province></brach_bank_province>");
		xml.append("<brach_bank_city></brach_bank_city>");
		xml.append("<brach_bank_name></brach_bank_name>");
		xml.append("<tran_amt>").append(tranAmt).append("</tran_amt>");
		xml.append("<currency>").append("CNY").append("</currency>");
		xml.append("<bsn_code>").append(bsnCode).append("</bsn_code>");
		xml.append("<cert_type>").append(certType).append("</cert_type>");
		xml.append("<cert_no>").append(certNo).append("</cert_no>");
		xml.append("<mobile></mobile>");
		xml.append("<remark></remark>");
		xml.append("<reserve></reserve>");
		xml.append("</body></message>");
		return xml.toString();
	}

}
